/* Copyright (C) 2008, 2009, 2010 Faindu GmbH, Switzerland.
* All Rights Reserved. The following is Source Code and is subject to all restrictions 
* on such code as contained in the license accompanying this project. */
package blocstac.editimage.base
{

import flash.display.BitmapData;

import flexunit.framework.TestCase;

public class ViewModel_sizeTest extends TestCase
{

    //==========================================================================
    //
    //  Test set up and tear down
    //
    //--------------------------------------------------------------------------  
	private var viewModel:ViewModel
	private var imageModel:ImageModel
	private var imageData:BitmapData
	
	override public function setUp(): void
	{
		imageModel = new ImageModel()
		viewModel = new ViewModel(imageModel)
		imageData = new BitmapData(10, 15)
	}
	
	override public function tearDown():void
	{
	}
	
    //==========================================================================
    //
    //  Tests
    //
    //--------------------------------------------------------------------------  
	[Test]
	public function test_imageWidth(): void
	{	
		imageModel.editedScaleX = 2
		imageModel.editedScaleY = 3
		assertEquals(0, viewModel.imageWidth)
		
		imageModel.updateImageData(imageData)
		assertEquals(20, viewModel.imageWidth)
	}

	[Test]
	public function test_imageHeight(): void
	{	
		imageModel.editedScaleX = 2
		imageModel.editedScaleY = 3
		assertEquals(0, viewModel.imageHeight)
		
		imageModel.updateImageData(imageData)
		assertEquals(45, viewModel.imageHeight)
	}

	[Test]
	public function test_imageViewWidthScaled(): void
	{	
		imageModel.editedScaleX = 2
		imageModel.editedScaleY = 3
		assertEquals(0, viewModel.imageViewWidth)
		
		imageModel.updateImageData(imageData)
		assertEquals(20, viewModel.imageViewWidth)
	}

	[Test]
	public function test_imageViewHeightScaled(): void
	{	
		imageModel.editedScaleX = 2
		imageModel.editedScaleY = 3
		assertEquals(0, viewModel.imageViewHeight)
		
		imageModel.updateImageData(imageData)
		assertEquals(45, viewModel.imageViewHeight)
	}
		
	[Test]
	public function test_componentWidth_and_Height_simple(): void
	{	
		assertEquals(0, viewModel.componentWidth)
		assertEquals(0, viewModel.componentHeight)
		
		imageModel.updateImageData(imageData)
		assertEquals(10, viewModel.componentWidth)
		assertEquals(15, viewModel.componentHeight)
	}

	[Test]
	public function test_componentWidth_and_Height_scaled(): void
	{	
		imageModel.editedScaleX = 2
		imageModel.editedScaleY = 3
		imageModel.updateImageData(imageData)
		
		assertEquals(20, viewModel.componentWidth)
		assertEquals(45, viewModel.componentHeight)
	}
	
	[Test]
	public function test_componentWidth_and_Height_with_rotation(): void
	{	
		imageModel.updateImageData(imageData)
		imageModel.angle = Math.PI / 2 
		viewModel.interactionEnds()
		
		assertEquals(15, viewModel.componentWidth) // flipped 10 / 15
		assertEquals(10, viewModel.componentHeight)
	}
}
}